package com.yeyaomai.dksns.flowis.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import com.yeyaomai.dksns.flowis.dao.BrowserDao;
import com.yeyaomai.dksns.flowis.domain.Browser;
import com.yeyaomai.dksns.flowis.page.PageImplResult;
import com.yeyaomai.dksns.flowis.page.PageRequestOrder;
import com.yeyaomai.dksns.flowis.page.SplitConstant;
import com.yeyaomai.dksns.flowis.service.BrowserService;

@Service
public class BrowserServiceImpl implements BrowserService {

	@Resource
	private BrowserDao browserDao;
	
	@Override
	public Browser getBrowserById(long id) {
		
		return browserDao.getBrowserById(id);
	}

	@Override
	public List<Browser> getBrowserByDay(Map<String, Object> map) {
		
		return browserDao.getBrowserByDay(map);
	}

	@Override
	public Browser getBrowserByTime(String fromDate, String toDate) {
		
		return browserDao.getBrowserByTime(fromDate, toDate);
	}

	@Override
	public Page<Browser> getDataPage(Map<String, Object> map,
			Integer currentpage) {
		long browserCount = browserDao.getBrowserCount(map);
		PageRequestOrder request = new PageRequestOrder(currentpage,
				SplitConstant.PAGE_SIZE);
		List<Browser> browserList = new ArrayList<Browser>();
		map.put("startNumber", request.start());
		map.put("endNumber", request.end());
		browserList = browserDao.getBrowserByDay(map);
		Page<Browser> result = new PageImplResult<Browser>(browserList,
				request, browserCount);
		return result;
	}

	@Override
	public List<Browser> getBrowserByName(Map<String, Object> map) {
		
		return browserDao.getBrowserByName(map);
	}

}
